﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using TracyGUI.View;
using SharedLib.WinFormMVCFramework;
using Tracy.DataModel;
using TracyGUI.View.EntryTabs;
using TracyGUI.Model;
using TracyGUI.View.UIComponent;
using System.Windows.Forms;
using System.Xml;

namespace TracyGUI.Controller.EntryTabs
{
    abstract class EntryTabPageViewControllerBase : ControllerBase<IEntryTabPageView>, IController<IEntryTabPageView>, ITabPageViewController
    {
        
        protected override IEntryTabPageView ResolveView()
        {
            return Tracy.TracyFacade.Instance.DIContainer.Resolve<IEntryTabPageView>();
        }
        private List<ITabPageViewController> _tabPages = new List<ITabPageViewController>();
        private ResourceTabPageViewController _resTabPage;

        protected ResourceTabPageViewController ResTabPage
        {
            get { return _resTabPage; }
        }
        private MediaFileTabPageViewController _fileTabPage;

        protected MediaFileTabPageViewController FileTabPage
        {
            get { return _fileTabPage; }
        }

        #region Public Interface
        public EntryTabPageViewControllerBase(string name, string text) : this()
        {
            View.Name = name;
            View.Text = text;
        }

        public EntryTabPageViewControllerBase()
        {
            _fileTabPage = new MediaFileTabPageViewController(this);
            _resTabPage = new ResourceTabPageViewController(this);
            AddSubTabPage(_fileTabPage);
            AddSubTabPage(_resTabPage);
        }

        //public void LoadResources(List<Resource> resources, bool clearView = true)
        //{
        //    ResTabPage.LoadResources(resources, clearView);
        //}
        
        //public void LoadMediaFiles(List<MediaFile> files, bool clearView = true)
        //{
        //    FileTabPage.LoadMediaFiles(files, clearView);
        //}

        public void AddSubTabPage(ITabPageViewController tabPageViewController)
        {
            _tabPages.Add(tabPageViewController);
            View.SubTabControl.TabPages.Add(tabPageViewController.View.TabPage);
        }

        ITabPageView IController<ITabPageView>.View
        {
            get { return View; }
        }
        #endregion



        public virtual void LoadViewState(ViewStateManager manager, System.Xml.XmlElement viewStateNode)
        {
            manager.LoadViewState(ResTabPage, viewStateNode);
            manager.LoadViewState(FileTabPage, viewStateNode);
        }

        public virtual void SaveViewState(ViewStateManager manager, System.Xml.XmlElement viewStateNode, System.Xml.XmlDocument doc)
        {
            manager.SaveViewState(ResTabPage, viewStateNode);
            manager.SaveViewState(FileTabPage, viewStateNode);
        }
    }
}
